//package com.example.demo.test;
//
//import com.beust.jcommander.internal.Maps;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Service;
//import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
//import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
//import software.amazon.awssdk.regions.Region;
//import software.amazon.awssdk.services.s3.model.PutObjectRequest;
//import software.amazon.awssdk.services.s3.model.S3Exception;
//import software.amazon.awssdk.services.s3.presigner.S3Presigner;
//import software.amazon.awssdk.services.s3.presigner.model.PresignedPutObjectRequest;
//import software.amazon.awssdk.services.s3.presigner.model.PutObjectPresignRequest;
//import software.amazon.awssdk.utils.IoUtils;
//
//import java.io.ByteArrayOutputStream;
//import java.io.File;
//import java.io.IOException;
//import java.io.InputStream;
//import java.net.*;
//import java.time.Duration;
//import java.util.Map;
//
//@Slf4j
//public class S3Service {
//
//    private final static String region = "cn-beijing";
//    private final static String bucket = "bucket-meizi";
//    private final static String ak = "597TPSH9P92HGHDVAMMY";
//    private final static String sk = "UvsQnXTbC7jKkfcBzlQ1q9Ccry5LUfXJFLM2QszR";
//    private final static String endpoint = "https://huabei-2.zos.ctyun.cn";
//
//
//    public static String createPresignedGetUrl(String keyName, Map<String, String> metadata) throws URISyntaxException {
//        log.info("S3Service--->createPresignedGetUrl--->keyName:{},metadata:{}", keyName, metadata);
//        URI uri = new URI(endpoint);
//        S3Presigner presigner = S3Presigner.builder().region(Region.of(region)).endpointOverride(uri).credentialsProvider(
//                StaticCredentialsProvider.create(AwsBasicCredentials.create(ak, sk))).build();
//
//        PutObjectRequest objectRequest = PutObjectRequest.builder()
//                .bucket(bucket)
//                .key(keyName)
//                .metadata(metadata)
//                .build();
//
//        PutObjectPresignRequest presignRequest = PutObjectPresignRequest.builder()
//                .signatureDuration(Duration.ofMinutes(10))  // The URL expires in 10 minutes.
//                .putObjectRequest(objectRequest)
//                .build();
//
//
//        PresignedPutObjectRequest presignedRequest = presigner.presignPutObject(presignRequest);
//        String myURL = presignedRequest.url().toString();
//        System.out.println(myURL);
//        System.out.println(presignedRequest.url().toExternalForm());
//        String url = presignedRequest.url().toExternalForm();
////        useHttpUrlConnectionToGet(url);
//        return url;
//    }
//
//    /* Use the JDK HttpURLConnection (since v1.1) class to do the download. */
////    public static byte[] useHttpUrlConnectionToGet(String presignedUrlString) {
////        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); // Capture the response body to a byte array.
////
////        try {
////            URL presignedUrl = new URL(presignedUrlString);
////            HttpURLConnection connection = (HttpURLConnection) presignedUrl.openConnection();
////            connection.setRequestMethod("GET");
////            // Download the result of executing the request.
////            try (InputStream content = connection.getInputStream()) {
////                IoUtils.copy(content, byteArrayOutputStream);
////            }
////            log.info("HTTP response code is " + connection.getResponseCode());
////
////        } catch (S3Exception | IOException e) {
////            log.error(e.getMessage(), e);
////        } catch (Exception e) {
////            throw new RuntimeException(e);
////        }
////        return byteArrayOutputStream.toByteArray();
////    }
//
//
//
//
//
//
//    public static void main(String[] args) throws URISyntaxException {
//        Map<String, String> metadata = Maps.newHashMap();
////        metadata.put("fileName","https://203.83.237.48/upload/vod/user1735982106105323/1736235387689137/origin.mp4");
////        String presignedGetUrl = createPresignedGetUrl("https://203.83.237.48/upload/vod/user1735982106105323/1736235387689137/origin.mp4", metadata);
////        log.info("DiskFileController--->detail--->presignedGetUrl:{}",presignedGetUrl);
//
//        metadata.put("fileName","upload/vod/user1735982106105323/1736235387689137/origin.mp4");
//        String presignedGetUrl = createPresignedGetUrl("upload/vod/user1735982106105323/1736235387689137/origin.mp4", metadata);
//        log.info("DiskFileController--->detail--->presignedGetUrl:{}",presignedGetUrl);
//    }
//}
